package com.inight.nightojbackenduserservice.controller.inner;


import com.inight.nightojbackendserviceclient.service.UserFeignClient;
import com.inight.nightojbackenduserservice.service.UserService;
import nightojbackendmodel.entity.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;


/**
 * 该服务仅是内部服务调用, 不暴露给前端
 */
@RestController
@RequestMapping("/inner")
public class UserInnerController implements UserFeignClient {

    // 调用用户的 service
    @Resource
    private UserService userService;

    /**
     * 根据用户id获取用户
     * @param userId
     * @return
     */
    @Override
    @GetMapping("/get/id")
    public User getById(@RequestParam("userId") long userId) {
        return userService.getById(userId);
    }

    /**
     * 根据id 列表获取用户列表
     * @param idList 这里可以传list 或者 set. 原本mybatis调用的就是 Collection
     * @return
     */
    @Override
    @GetMapping("/get/ids")
    public List<User> listByIds(@RequestParam("idList") Collection<Long> idList) {
        return userService.listByIds(idList);
    }
}
